package br.com.werp.regras.suporte.integracao;

import br.com.werp.regras.geral.integracao.MasterDAO;
import br.com.werp.regras.geral.util.Constantes;
import br.com.werp.regras.geral.util.Util;
import br.com.werp.regras.geral.vos.tabelas.Hd;

import java.sql.Connection;

import java.util.List;
import java.util.ResourceBundle;


/**
 * @author Italo
 *
 *07/07/2006
 */
public class HdDAO extends MasterDAO {
    private static HdDAO hdDAO;

    private HdDAO(String banco) throws Exception {
        super(banco);
    }

    public static HdDAO getHdDAO() throws Exception {
        if (hdDAO == null) {
            ResourceBundle bundle = ResourceBundle.getBundle(Constantes.CONFIG);
            hdDAO = new HdDAO(bundle.getString(Constantes.BANCO));
        }

        return hdDAO;
    }

    public void salvarHD(Hd hd, Object key) throws Exception {
        Connection connection = validarTransacao(key);
        inserirVO(connection, hd, new String[] { "hadk_id" });
    }

    public void atualizarHD(Hd hd, Object key) throws Exception {
        Connection connection = validarTransacao(key);
        atualizarVO(connection, hd, new String[] { "hadk_id" });
    }

    public List pesquisarHD(Hd hd) throws Exception {
        Connection connection = getConexao();

        try {
            String where = "";

            if (!Util.isNullOrEmpty(hd.getHadk_marca())) {
                where += (" and hadk_marca like " +
                aspasLike(hd.getHadk_marca()));
                hd.setHadk_marca(null);
            }

            if (!Util.isNullOrEmpty(hd.getHadk_modelo())) {
                where += (" and hadk_modelo like " +
                aspasLike(hd.getHadk_modelo()));
                hd.setHadk_modelo(null);
            }

            return pesquisarVO(connection, hd,where);
        } finally {
            liberaConeccao(connection);
        }
    }

    public void excluirHD(Hd hd, Object key) throws Exception {
        Connection connection = validarTransacao(key);
        excluirVO(connection, hd);
    }
}
